#!/bin/bash
read -p "Enter Mysql Root Password: " MYSQL_PASS

# daloRadius
wget http://downloads.sourceforge.net/project/daloradius/daloradius/daloradius0.9-9/daloradius-0.9-9.tar.gz
tar zxf daloradius-0.9-9.tar.gz
mkdir -p /styx/wwwroot/
cp -R daloradius-0.9-9 /styx/wwwroot/dalo
chown lighttpd:lighttpd /styx/wwwroot/dalo -R
pushd /styx/wwwroot/dalo
chmod 644 /styx/wwwroot/dalo/library/daloradius.conf.php

mysql -uroot -p${MYSQL_PASS} radius < contrib/db/fr2-mysql-daloradius-and-freeradius.sql

mysql -uroot radius -p${MYSQL_PASS} -e "INSERT INTO \`radusergroup\` VALUES ('vpn','vpnusers',1);INSERT INTO \`radgroupcheck\` VALUES (NULL,'vpnusers','Simultaneous-Use',':=','100');INSERT INTO \`radcheck\` VALUES (NULL,'vpn','User-Password',':=','vpn');" 

# edit database configs
sed -i 's/'"\$configValues\['CONFIG_DB_USER'\].*$"/"\$configValues\['CONFIG_DB_USER'\] = 'radius';"'/g' library/daloradius.conf.php
sed -i 's/'"\$configValues\['CONFIG_DB_PASS'\].*$"/"\$configValues\['CONFIG_DB_PASS'\] = 'radius_overgfw';"'/g' library/daloradius.conf.php
sed -i 's/'"\$configValues\['CONFIG_PATH_DALO_VARIABLE_DATA'\].*$"/"\$configValues\['CONFIG_PATH_DALO_VARIABLE_DATA'\] = '\/styx\/wwwroot\/dalo\/var';"'/g' library/daloradius.conf.php

popd

#Surf to http://yourip/daloradius
#Login:
#          username: administrator
#          password: radius
